/*
 * GL_Window.h
 */

#ifndef GL_WINDOW_H_
#define GL_WINDOW_H_

/* Need to link opengl32, glu32, gdi32 */
#include <windows.h>
#include <gl/gl.h>
#include <gl/glu.h>

/* For ARB multisampling (AA) */
#include <gl/wglext.h>		//WGL extensions
#include <gl/glext.h>		//GL extensions

#include <iostream>

#define WM_TOGGLEFULLSCREEN (WM_USER+1)			// Application Define Message For Toggling

/* Declairations We'll Use for ARB multisampling */
#define WGL_SAMPLE_BUFFERS_ARB		 0x2041
#define WGL_SAMPLES_ARB			     0x2042


struct Keys {									// Structure For Keyboard Stuff
	bool keyDown [256];								// Holds TRUE / FALSE For Each Key
	bool keyNoticed [256];
};												// Keys

struct Application{									// Contains Information Vital To Applications
	HINSTANCE		hInstance;						// Application Instance
	const char*		className;						// Application ClassName
};										// Application

struct GL_WindowInit{									// Window Creation Info
	Application*		application;				// Application Structure
	char*				title;						// Window Title
	int					width;						// Width
	int					height;						// Height
	int					bitsPerPixel;				// Bits Per Pixel
	BOOL				isFullScreen;				// FullScreen?
};

class GL_Window
{
public:
	GL_Window(char *className, HINSTANCE hInstance);
	virtual ~GL_Window();

	bool registerWindowClass(WNDPROC windowProc);
	bool createWindowGL();
	bool toggleFullScreen();
	bool toggleMultisample();
	//void terminateApplication();
	void processMessages();
	void swapBuffers();
	HDC getHDC();

	LRESULT CALLBACK windowProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);

	char*				title;
	int					width;
	int					height;
	int					bitsPerPixel;
	bool				fullScreen;
	bool				multisample;

	Keys				keys;						// Key Structure
	bool				isVisible;					// Window Visible?
	bool				isRunning;

	bool				terminate;

private:
	const char			*className;
	HINSTANCE			hInstance;
	HGLRC				hRC;						// Rendering Context
	HWND				hWnd;						// Window Handle
	HDC					hDC;						// Device Context

	MSG					msg;

	bool				firstRun;
	bool				arbMultisampleSupported;
	int					arbMultisampleFormat;

	bool WGLisExtensionSupported(const char *extension);
	bool initMultisample();
	void reshapeGL(int width, int height);
	bool changeScreenResolution(int width, int height, int bitsPerPixel);
	bool destroyWindowGL();



};

#endif /* GL_WINDOW_H_ */
